package com.ljkj.cordial.chat.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.ljkj.cordial.chat.fragment.FileAnnexFragment;
import com.ljkj.cordial.chat.fragment.FilePictureFragment;
import com.ljkj.cordial.chat.fragment.FileVideoFragment;
import com.ljkj.cordial.chat.fragment.FileVoiceFragment;

public class FileMPagerAdapter extends FragmentPagerAdapter {
    private FileMAdapter.OnFileItemClickListener onFileItemClickListener;

    public FileMPagerAdapter(FragmentManager fm, FileMAdapter.OnFileItemClickListener onFileItemClickListener) {
        super(fm);
        this.onFileItemClickListener = onFileItemClickListener;
    }


    @Override
    public Fragment getItem(int i) {
        switch (i) {
            case 0:
                FileVideoFragment videoFragment = new FileVideoFragment();
                videoFragment.setListener(onFileItemClickListener);
                return videoFragment;
            case 1:
                FilePictureFragment pictureFragment = new FilePictureFragment();
                pictureFragment.setListener(onFileItemClickListener);
                return pictureFragment;
            case 2:
                FileVoiceFragment voiceFragment = new FileVoiceFragment();
                voiceFragment.setListener(onFileItemClickListener);
                return voiceFragment;

            case 3:
                FileAnnexFragment annexFragment = new FileAnnexFragment();
                annexFragment.setListener(onFileItemClickListener);
                return annexFragment;
        }
        return null;
    }

    public void getItemClickListener(int i) {
        Fragment fragment = getItem(i);
        if (fragment instanceof FileVideoFragment) {
            FileVideoFragment videoFragment = (FileVideoFragment) fragment;
            videoFragment.setListener(onFileItemClickListener);
        }
        if (fragment instanceof FilePictureFragment) {
            FilePictureFragment videoFragment = (FilePictureFragment) fragment;
            videoFragment.setListener(onFileItemClickListener);
        }
        if (fragment instanceof FileVoiceFragment) {
            FileVoiceFragment videoFragment = (FileVoiceFragment) fragment;
            videoFragment.setListener(onFileItemClickListener);
        }
        if (fragment instanceof FileAnnexFragment) {
            FileAnnexFragment videoFragment = (FileAnnexFragment) fragment;
            videoFragment.setListener(onFileItemClickListener);
        }
    }

    @Override
    public int getCount() {
        return 4;
    }
}
